public class test3 {
    /**
     * Definition for singly-linked list.
     * public class ListNode {
     *     int val;
     *     ListNode next;
     *     ListNode() {}
     *     ListNode(int val) { this.val = val; }
     *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
     * }
     */
    class Solution {
        public ListNode reverseBetween(ListNode head, int left, int right) {
            ListNode dummyNode = new ListNode(-1,head);
            ListNode p0 = dummyNode;
            for(int i = 0;i<left-1;i++){
                p0 = p0.next;
            }
            ListNode pre = null;
            ListNode cur = p0.next;
            ListNode tmp = null;
            for(int i = 0;i<right-left+1;i++){
                tmp = cur.next;
                cur.next = pre;
                pre = cur;
                cur = tmp;
            }
            //改变的只是中间的指向，“1”->“2”还是没变
            p0.next.next = cur;
            p0.next = pre;//先变了next就找不到nextnext了
            return dummyNode.next;
        }
    }
}
